package cn.hznc.controller.test.strategy;

import cn.hutool.core.collection.CollectionUtil;
import cn.hznc.constant.CommonConstant;
import cn.hznc.controller.service.testTask.TestTaskService;
import cn.hznc.domain.entity.ToolForkInfoEntity;
import cn.hznc.mapper.ToolForkInfoMapper;
import cn.hznc.utils.CommonUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.apache.commons.lang.StringUtils;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;

/**
 * @Author：Administrator
 * @Date：2024/2/22 15:20
 */
@Component
public class ZccGetToolForkInfoDataStrategy implements GetToolForkInfoDataStrategy{

    @Resource
    private ToolForkInfoMapper toolForkInfoMapper;

    @Resource
    private TestTaskService testTaskService;

    @Override
    public void syncToolForkInfoData() {
        String s1 = CommonConstant.USAGE_ADRESS+"/ZeusoftWebService.svc/api/GetToolData";
        String s2 = CommonConstant.USAGE_ADRESS+"/ZeusoftWebService.svc/api/GetBladeData";
        String s3 = CommonConstant.USAGE_ADRESS+"/ZeusoftWebService.svc/api/GetToolHolderData";
        //toolForkInfoMapper.delete(new QueryWrapper<>());
        List<ToolForkInfoEntity> existList = toolForkInfoMapper.selectList(new QueryWrapper<>());
        existList = existList
                .stream()
                .filter(toolForkInfoEntity -> StringUtils.isNotBlank(toolForkInfoEntity.getPartno()))
                .collect(Collectors.toList());
        List<String> partnos = new ArrayList<>();
        if(CollectionUtil.isNotEmpty(existList)){
            partnos = existList.stream().map(ToolForkInfoEntity::getPartno).collect(Collectors.toList());
        }
        testTaskService.parseToolInfoJson(CommonUtil.getData(s1) , existList , partnos);
       //testTaskService.parseToolInfoJson(CommonUtil.getData(s2) , existList , partnos);
       //testTaskService.parseToolInfoJson(CommonUtil.getData(s3) , existList , partnos);
    }
}
